package system.security.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import system.security.dao.AuthorityDao;
import system.security.entity.Authority;
import system.security.service.AuthorityService;


@Service("authorityService")
public class AuthorityServiceImpl implements AuthorityService {

	@Autowired
	AuthorityDao authorityDao;
	
	@Transactional(readOnly=true)
	@Override
	public Authority getById(int authorityId) {
		Authority authority = authorityDao.get(authorityId);
		return authority;
	}

	@Override
	public Authority findByName(String authorityname) {
			List<Authority> list = authorityDao.findByProperty("authorityname", authorityname);
			if(!list.isEmpty()){
				return list.get(0);
			}
			return null;		
	}

	@Override
	@Transactional(readOnly = true)
	public List<Authority> getAll() {
		return authorityDao.list();
	}
	
	@Override
	public void save(Authority authority) throws Exception {
			authorityDao.saveOrUpdate(authority);
	}

	@Override
	public void delete(int authorityId) {
		authorityDao.remove(authorityId);
	}
	
	@Override
	public void delete(Authority authority){
		authorityDao.remove(authority);		
	}

	
}
